﻿<%@ Page Language="C#" MasterPageFile="~/Pages/Base/ListItemBase.master" CodeFile="~/Pages/Base/ListItemBase.cs" Inherits="ListItemBasePage" %>

<asp:Content ID="content" runat="server" ContentPlaceHolderID="footContent">
<div runat="server" id="contentDiv">
    <asp:Button ID="addPMButton" runat="server" Text="新增篇名" style="margin-left: 37px" />
</div>
</asp:Content>

<asp:Content ID="message" runat="server" ContentPlaceHolderID="messageContent">
    <asp:Label ID="errorLabel" runat="server" ForeColor="Red" />
</asp:Content>

<script runat="server">
    
    /// <summary>
    /// 数据库交互对象
    /// </summary>

    private StateGrid.DLBK.DLBK_DAO dao = new StateGrid.DLBK.DLBK_DAO();

    private IList<StateGrid.DLBK.DLBK_PM> data;

    private string catalog;
    private string keyword;

    protected override void DoInit()
    {        
        catalog = ParseStringQuery("catalog");
        keyword = ParseStringQuery("keyword");

        if (null == catalog)
        {
            StateGrid.GlobalMethod.RedirectLogin(Response);
            return;
        }
        this.addPMButton.Click += new EventHandler(addPMButton_Click);

        if (catalog.Length == 6)
            this.contentDiv.Visible = true;
        else
            this.contentDiv.Visible = false;
    }

    void addPMButton_Click(object sender, EventArgs e)
    {
        Response.Redirect(StateGrid.GlobalVariables.GlobalDLBK.ADDPM_PAGE+"?flbm="+this.catalog);
    }

    protected override void SetItemFields()
    {
        RegisterKeyField("id");
        
        AddBoudField("日期", "rq", 12,15);
        AddBoudField("标题", "bt",24,50);
        AddBoudField("作者", "zz", 12, 25);
        AddHyperLinkField("修改",
                   StateGrid.GlobalVariables.GlobalDLBK.EDITPM_PAGE + "?id={0}",
                   new String[] { "id" }); 
    }

    protected override int GetItemCount()
    {
        return dao.GetCountSomeDLBK_PM(catalog);
    }

    protected override object GetItemSource(int begin, int end)
    {
        data = dao.GetSomeDLBK_PM(catalog, begin, end);
        return data;
    }

    protected override bool OnDelete(DataKey dataKey, out string message)
    {
        bool ret = dao.DeleteDLBK_PMByID((int)dataKey.Value, ((StateGrid.User.User)Session["login"]).name);

        if (ret)
        {
            message = "删除成功";
        }
        else
        {
            message = "删除失败";
        }
        return ret;
    }

    //显示删除按钮
    protected override Boolean HasDeleteField()
    {
        return true;
    }

</script>
